const db = wx.cloud.database();
const grzl = db.collection('grzl')
Page({
  data: {
    zc: '',
    passW: ''
  },
  indexBtnClick(){
    wx.navigateTo({
      url: '../../pages/index/index',
    })
  },
  userNameInput: function (e) {
    this.setData({
      zc: e.detail.value
    })
  },
  passWordInput: function (e) {
    this.setData({
      passW: e.detail.value
    })
  },
 loginBtnClick: function (a) {
    var that = this
    if (that.data.zc.length == 0 || that.data.passW.length == 0) {
      wx.showModal({
        title: '温馨提示：',
        content:'用户名或密码不能为空！',
        showCancel:false
      })
    } else {
      db.collection('grzl').get({
        success(res){
          console.log('res.data')
          if(res.data[0] == null){
            wx.showModal({
              title: '用户名错误',
              content: '用户名错误'
            });
          }
          else{
           if (that.data.passW == res.data[0].dz){
             wx.switchTab({
               url: '../../pages/shouye/shouye',
             })
           }
           else{
             wx.showModal({
               title: '密码错误',
               content: '密码错误'
             });
           }
          }
        }

      })
    }
  }
})